package com.opensource.svgaplayer.bitmap;

import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
import ohos.media.image.common.PixelFormat;
import ohos.media.image.common.Size;

/**
 * ex.
 *
 * @author wl
 * @since 2021-06-28
 */
public abstract class SVGABitmapDecoder {
    public PixelMap decodeBitmapFrom(Object data, int reqWidth, int reqHeight) {
        ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
        decodingOptions.desiredPixelFormat = PixelFormat.UNKNOWN;
        decodingOptions.desiredSize = new Size(reqWidth, reqHeight);
        PixelMap bitmap = this.onDecode(data, decodingOptions);
        if (!(reqWidth > 0 && reqHeight > 0)) {
            return bitmap;
        } else {
            decodingOptions.sampleSize = BitmapSampleSizeCalculator.getInstance().calculate(bitmap.getImageInfo().size, decodingOptions);
            return this.onDecode(data, decodingOptions);
        }
    }

    /**
     * onDecode
     *
     * @param var1 数据
     * @param ops  配置
     * @return PixelMap
     */
    public abstract PixelMap onDecode(Object var1, ImageSource.DecodingOptions ops);
}
